<?php
class LoginAction extends Action {
	public function islogin()
	{
		if(isset($_SESSION['member']))
		{
			return true;
		}
		else
		{
			$this->redirect('Login/login');
		}
	}
	
	
	//登录函数
	public function login() {
		unset($_SESSION['member']);
		$this->display ( 'login' );
	}
	
	
	
	//验证码
	public function verify() {
		import ( 'ORG.Util.Image' );
		Image::buildImageVerify ();
	}
	
	public function loginchk() {
		if(md5($_POST['checkcode']) != $_SESSION['verify'])
		{
			$this->error('验证码错误');
		}
		$User = M('admins');
		if(!$User->autoCheckToken($_POST))
		{
			$this->error('令牌验证错误');
		}
		
		$where = 'username = \''.$_POST['username'] . '\' and password = \''.md5($_POST['password']).'\'';
		if(!($user = $User->where($where)->find()))
		{
			$this->error('用户名或密码错误');
		}
		$_SESSION['member'] = $user;
		$this->redirect('Index/index');
	}
	
	public function Logout()
	{
		unset($_SESSION['member']);
		$this->redirect('Index/index');
	}
}